/*
   MSR.cpp
   
   Copyright (C) 2006 LinuxOne, Inc. <Republic of korea>

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Lessor General Public License for more details.

   You should have received a copy of the GNU Lessor General Public
   License along with this library; if not, write to the Free Software
   Foundation, inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

   Hyunjin Kim <mgc521@linuxone.co.kr>

   LinuxOne, Inc., hereby disclaims all copylight
   written by Hyunjin Kim, 20 December 2006
*/

#include <services/MSRService.h>

namespace booyopos
{

namespace services
{

CMSRService::CMSRService()
{
	deviceServiceDescription = "BooyoPOS Magnetic Striper Reader Device";
	deviceServiceVersion = 0;
	physicalDeviceDescription = "Valcretec Magnetic Striper Reader Device";
	physicalDeviceName = "MSR";
}

CMSRService::~CMSRService()
{
}

/* Capabilities */
bool
CMSRService::GetCapISO()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capISO;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapJISOne()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capJISOne;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapJISTwo()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capJISTwo;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetCapPowerReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capPowerReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapTransmitSentinels()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capTransmitSentinels;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapStatisticsReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capStatisticsReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapUpdateStatistics()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capUpdateStatistics;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapCompareFirmwareVersion()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capCompareFirmwareVersion;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetCapUpdateFirmware()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capUpdateFirmware;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetCapWritableTracks()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return capWritableTracks;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Properties */
std::string
CMSRService::GetAccountNumber()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return accountNumber;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetAutoDisable()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return autoDisable;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetAutoDisable(bool autoDisable)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::autoDisable = autoDisable;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetDataCount()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return dataCount;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetDataEventEnabled()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return dataEventEnabled;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetDataEventEnabled(bool dataEventEnabled)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::dataEventEnabled = dataEventEnabled;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetDecodeData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return decodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetDecodeData(bool decodeData)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::decodeData = decodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetErrorReportingType()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return errorReportingType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetErrorReportingType(int errorReportingType)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::errorReportingType = errorReportingType;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetExpirationDate()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return expirationDate;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetFirstName()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return firstName;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetMiddleInitial()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return middleInitial;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetParseDecodeData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return parseDecodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetParseDecodeData(bool parseDecodeData)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::parseDecodeData = parseDecodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetServiceCode()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return serviceCode;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetSuffix()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return suffix;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetSurname()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return surname;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

std::string
CMSRService::GetTitle()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return title;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

char*
CMSRService::GetTrack1Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return track1Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

char*
CMSRService::GetTrack1DiscretionaryData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return track1DiscretionaryData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

char*
CMSRService::GetTrack2Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return track2Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

char*
CMSRService::GetTrack2DiscretionaryData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return track2DiscretionaryData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

char*
CMSRService::GetTrack3Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return track3Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetTracksToRead()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return tracksToRead;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetTracksToRead(int tracksToRead)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::tracksToRead = tracksToRead;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetPowerNotify()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return powerNotice;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetPowerNotify(int powerNotice)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::powerNotice = powerNotice;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetPowerState()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return powerState;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

char*
CMSRService::GetTrack4Data()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return track4Data;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

bool
CMSRService::GetTransmitSentinels()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return transmitSentinels;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetTransmitSentinels(bool transmitSentinels)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::transmitSentinels = transmitSentinels;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetEncodingMaxLength()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return encodingMaxLength;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

int
CMSRService::GetTracksToWrite()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return tracksToWrite;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::SetTracksToWrite(int tracksToWrite)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		CMSRService::tracksToWrite = tracksToWrite;
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Methods */
void
CMSRService::WriteTracks(std::string data, int timeout)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

/* Statistics */
void
CMSRService::ClearInput()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::ResetStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::RetrieveStatistics(std::string statisticsBuffer[])
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::UpdateStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CMSRService::CompareFirmwareVersion(std::string firmwareFileName, int* result)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::UpdateFirmware(std::string firmwareFileName)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

void
CMSRService::ClearInputProperties()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		/* TO DO */
	}
	catch(CByException bye)
	{
		throw bye;
	}
}

} // namespace services

} // namespace booyopos
